//
// Created by mongobaba on 2021/6/7.
//

#include "unit_test.h"
#include "json_validator.h"

// 空分支
TEST(parse_characters_empty) {
    json_validator validator("");
    ASSERT_EQ(true, validator.parse_characters());
    ASSERT_EQ(std::string(""), validator.left());
}

// 正常情况
TEST(parse_characters) {
    json_validator validator(R"(hello中文\n"ab)");
    ASSERT_EQ(true, validator.parse_characters());
    ASSERT_EQ(std::string(R"("ab)"), validator.left());
}

// 异常情况，非法转义
TEST(parse_characters_invalid_escape) {
    json_validator validator(R"(\px)");
    ASSERT_EQ(false, validator.parse_characters());
    ASSERT_EQ(std::string("px"), validator.left());
}

// 异常情况，非法unicode编码
TEST(parse_characters_invalid_unicode) {
    json_validator validator(R"(\uab0x)");
    ASSERT_EQ(false, validator.parse_characters());
    ASSERT_EQ(std::string("x"), validator.left());
}
